﻿@model iChip.Hotspots.Models.IndexObject
@{
    ViewBag.Title = "Splash";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section id="slider">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                @if (Model.Splash != null)
                {
                    @Html.Raw(Model.Splash.Splash_Content);
                }
            </div>
        </div>
    </div>
</section>
@if (Model.Fields != null && Model.Fields.Count > 0)
{
    <section>
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="contact-form">
                        <h2 class="title text-center">NHẬP THÔNG TIN ĐỂ TRUY CẬP WIFI</h2>
                        <div id="main-contact-form" class="contact-form row">
                            @foreach (var item in Model.Fields)
                            {
                                <div class="form-group col-md-12">
                                    @if (item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.String || item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.Email) // string => textbox
                                    {
                                        @Html.TextBoxFor(m => item.Field_Name, new { @class = "form-control", id = @item.Field_Id, @Value = string.Empty, placeholder = @item.Field_Name });
                                    }
                                    else if (item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.Textarea) // textarea
                                    {
                                        @Html.TextArea(item.Field_Name, new { @class = "form-control", @Value = string.Empty, id = @item.Field_Id, placeholder = @item.Field_Name })
                                    }
                                    else if (item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.Dropdownlist)
                                    {
                                        var obj = Model.DicSelectListItem[item.Field_Id];
                                        @Html.DropDownListFor(m => m.FieldValue_Id, obj, new { @class = "form-control" })
                                    }
                                    else if (item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.Radiobuttonlist)
                                    {
                                        var obj = Model.DicSelectListItem[item.Field_Id];
                                        @Html.Label(item.Field_Name,  new { Text = @item.Field_Name})
                                        foreach (var objItem in obj)
                                        {
                                            @Html.RadioButtonFor(m => objItem.Value, new { @class = "form-control" }) @objItem.Text
                                        }
                                    }
                                    else if (item.FieldType_Id == (int)iChip.Hotspots.Commons.Enums.FieldType.Checkbox)
                                    {
                                        var obj = Model.DicSelectListItem[item.Field_Id];
                                        @Html.Label(item.Field_Name, new { Text = @item.Field_Name})
                                        foreach (var objItem in obj)
                                        {
                                            @Html.CheckBox("chk_" + @objItem.Value, false, new { @Value = @objItem.Value })
                                        }
                                    }
                                </div>
                            }
                            <div class="form-group col-md-12">
                                @if (Model.Method_Type == iChip.Hotspots.Commons.Enums.MethodType.Survey.ToString())
                                {
                                    <button type="submit" class="btn btn-primary pull-right" onclick="PostFormData()"><i class="icon-ok"></i> Truy cập Wifi</button>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
}
@section Scripts {
    <script>
        var mac = '@ViewBag.Mac';
        var method_type = '@ViewBag.Method_Type';
        var hotspot_mac = '@ViewBag.Hotspot_Mac';
        var user_type = '@ViewBag.User_Type';
        function PostFormData() {
            var objRequest = [];
            var objForm = $("[name='item.Field_Name']");
            if ($(objForm).length > 0) {

                for (var i = 0; i < $(objForm).length; i++) {
                    var objItem = {};
                    objItem.Id = parseInt($(objForm)[i].id);
                    objItem.Value = $($(objForm)[i]).val();
                    objRequest.push(objItem);
                }
            }
            console.log("Thu cai",objRequest);

            $.ajax({
                method: "POST",
                url: "@Url.Action("PostInfo","FrontEnd")",
                data: JSON.stringify({
                    objRequest: objRequest,
                    method_type: method_type,
                    hotspot_mac: hotspot_mac,
                    user_type: user_type,
                    mac: mac,
                    urlRedirect: '@ViewBag.UrlRedirect'
                }),
                contentType: "application/json",
            })
            .done(function (msg) {
                if (msg.Status == 1) {

                }
                else {
                    alert(msg.Message);
                }
                connect();
            });


        }
    </script>
}